//独立的部门菜单的选择弹出层

function openDeptSelecter(pid,callBack){
	layui.use(['form', 'table','layer','treeTable'], function () {
	    var form = layui.form;
	    var table = layui.table;
		var laydate = layui.laydate;
		var layer = layui.layer;
		var treeTable = layui.treeTable;
		
		 //弹出层
		var selDeptIndex;
		var url;
		var tableSelectObj;  //回显表格对象
		
			selDeptIndex=layer.open({     //打开弹层
				 type: 1,
				 title:'选择部门',
				 content:'<div style="padding:5px"><table class="layui-hide" id="deptSelectTable" lay-filter="deptTable"></table></div> ',
				 area:['700px','600px'],
				 btn:['<span class="layui-icon layui-icon-ok"></span>确定'],   //确定按钮
				 btnAlign:'c',   //按钮居中
				 yes:function(index){    //确定回调函数
					var ckData = tableSelectObj.checkStatus();  //获取选中行的对象
					console.log(ckData);
					callBack(ckData[0].id,ckData[0].title);
					layer.close(selDeptIndex);   //关闭弹层
				 },
				 success:function(index){
	
					   tableSelectObj=  treeTable.render({   //渲染表格
					 	    tree: {
					 			iconIndex: 2,                // 折叠图标显示在第几列
					 			idName: 'id',       // 自定义id字段的名称
					 			pidName: 'pid',         // 自定义标识是否还有子节点的字段名称
					 			isPidData: true              // 是否是pid形式数据
					 		},
					 		elem: '#deptSelectTable',
					 		cellMinWidth:true,
					         cols: [
					             {type: "numbers"},
					             {type: "radio"},
					 			 {field: 'title',title: '部门名称',width:180},
					             {field: 'id', title: 'ID', align:"center"},     
					             {field: 'remark',title: '部门备注', align: "center"},
					             {field: 'address',title: '部门地址', align: "center"},
					         ],
					 	    reqData: function(data, callback) {
					 			// 在这里写ajax请求，通过callback方法回调数据
					 			$.get(api+'dept/loadAllDept', function (res) {
					 			 callback(res.data);
								 tableSelectObj.setChecked(pid)  //设置回调值
					 			 // console.log(res.data)
					 			});
					 		}
					     });		
				 }
			});
		});	
}






//独立的菜单的选择弹出层

function openMenuSelecter(pid,callBack){
	layui.use(['form', 'table','layer','treeTable'], function () {
	    var form = layui.form;
	    var table = layui.table;
		var laydate = layui.laydate;
		var layer = layui.layer;
		var treeTable = layui.treeTable;
		
		 //弹出层
		var selDeptIndex;
		var url;
		var tableSelectObj;  //回显表格对象
		
			selDeptIndex=layer.open({     //打开弹层
				 type: 1,
				 title:'选择菜单',
				 content:'<div style="padding:5px"><table class="layui-hide" id="deptSelectTable" lay-filter="deptTable"></table></div> ',
				 area:['700px','600px'],
				 btn:['<span class="layui-icon layui-icon-ok"></span>确定'],   //确定按钮
				 btnAlign:'c',   //按钮居中
				 yes:function(index){    //确定回调函数
					var ckData = tableSelectObj.checkStatus();  //获取选中行的对象
					console.log(ckData);
					callBack(ckData[0].id,ckData[0].title);
					layer.close(selDeptIndex);   //关闭弹层
				 },
				 success:function(index){
					   tableSelectObj=  treeTable.render({   //渲染表格
					 	    tree: {
					 			iconIndex: 2,                // 折叠图标显示在第几列
					 			idName: 'id',       // 自定义id字段的名称
					 			pidName: 'pid',         // 自定义标识是否还有子节点的字段名称
					 			isPidData: true,              // 是否是pid形式数据
								 openName: 'spread'  // 自定义默认展开的字段名
					 		},
					 		elem: '#deptSelectTable',
					 		cellMinWidth:true,
						   cols: [
							   {type: "numbers"},
							   {type: "radio"},
							   {field: 'title',title: '菜单名称'}, 
								// {field: 'id', title: 'ID', align:"center"},
							   {field: 'type',title: '类型', align: "center",templet: function (d) {
									   if (d.type == 'topmenu') {
										   return '<span class="layui-badge layui-bg-red">顶部菜单</span>';
									   }
									   if (d.type == 'leftmenu') {
										   return '<span class="layui-badge layui-bg-blue">左侧菜单</span>';
									   } else {
										   return '<span class="layui-badge-rim layui-bg-green">权限菜单</span>';
									   }
								   }},
							{field: 'typecode',title: '编码', align: "center"},
						   ],
						   reqData: function(data, callback) {
							// 在这里写ajax请求，通过callback方法回调数据
							$.get(api+'menu/loadMenu', function (res) {
							 callback(res.data);
							  tableSelectObj.setChecked(pid)
							});
					   }
					     });		
				 }
			});
		});	
}